package com.jy.modules.cims.common.controller;

import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Autowired;

import com.jy.modules.cims.data.dto.CimsBaseDto;
import com.jy.platform.api.org.SessionAPI;
import com.jy.platform.api.org.UserInfo;
import com.jy.platform.restservice.web.base.BaseController;

/**
 * 合作机构用的控制器
 * @author JY-IT-D001
 *
 */
public class CimsBaseController extends BaseController {
	
	@Autowired
    private SessionAPI sessionAPI;
	
	/**
	 * 新增数据时初始化默认数据
	 * @param dto
	 * @return
	 */
	protected CimsBaseDto initInsertParam(CimsBaseDto dto){
		if(dto==null){
        	dto = new CimsBaseDto();
        }
		UserInfo userInfo = sessionAPI.getCurrentUserInfo();
        if(userInfo != null){
        	Long userId = userInfo.getUserId();
        	dto.setCreateBy(userId.toString());
        }
		dto.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return dto;
    }
	/**
	 * 修改数据时初始化默认数据
	 * @param dto
	 * @return
	 */
	protected CimsBaseDto initUpdateParam(CimsBaseDto dto){
        if(dto==null){
        	dto = new CimsBaseDto();
        }
        UserInfo userInfo = sessionAPI.getCurrentUserInfo();
        if(userInfo != null){
        	Long userId = userInfo.getUserId();
        	dto.setModifyBy(userId.toString());
        }
		dto.setModifyTime(new Timestamp(System.currentTimeMillis()));
        return dto;
    }
	
}
